﻿using System;
using System.IO;
using System.Reflection;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using System.Xml;
using System.Xml.Linq;
using LotroTweeter.Engine;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Rhino.Mocks;
using LotroTweeter;

namespace LotroTweeter.UnitTests.Engine.LotroDataAPI
{
    /// <summary>
    /// Summary description for LotroDataApiConnectionHasBeenEstablished
    /// </summary>
    [TestClass]
    public class LotroDataApiConnectionHasBeenEstablished
    {

        [TestMethod]
        public void ShouldReturnCurrentKinRoster()
        {
            var thisAssembly = Assembly.GetExecutingAssembly();
            var kinRosterSource = thisAssembly.GetManifestResourceStream("LotroTweeter.UnitTests.KinRosterBefore.xml");
            var xmlReader = XmlReader.Create(kinRosterSource);
            var kinRosterBefore = XDocument.Load(xmlReader).Root;
            var connection = MockRepository.GenerateMock<ILotroConnector>();
            connection.Expect(c => c.GetKinRoster("")).Return(kinRosterBefore);

            var result = connection.GetKinRoster("");
            
            if (result != null)
            {
                var characterCount = (from r in result.Descendants("character")
                                      select r).Count();
                Assert.IsTrue(characterCount > 0);
            }
            else
            {
                Assert.Fail();
            }
        }

        [TestMethod]
        public void ShouldReturnCharacterStats()
        {
            var thisAssembly = Assembly.GetExecutingAssembly();
            var dataSource = thisAssembly.GetManifestResourceStream("LotroTweeter.UnitTests.CharacterStatsBefore.xml");
            var xmlReader = XmlReader.Create(dataSource);
            var characterDataBefore = XDocument.Load(xmlReader).Root;
            var connection = MockRepository.GenerateMock<ILotroConnector>();
            connection.Expect(c => c.GetCharacterData("Valdidar")).Return(characterDataBefore);

            var result = connection.GetCharacterData("Valdidar");

            if (result != null)
            {
                var statCount = (from r in result.Descendants("stat")
                                      select r).Count();
                Assert.IsTrue(statCount > 0);
            }
            else
            {
                Assert.Fail();
            }

        }
    }

}
